package com.woniuxy.springsecurity.controller;

import com.woniuxy.springsecurity.entity.ResponseResult;
import com.woniuxy.springsecurity.entity.User;
import com.woniuxy.springsecurity.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author author
 * @Create 2023-10-26 15:32
 */
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/user/login")
    public ResponseResult login(@RequestBody User user, HttpServletResponse response){
        System.out.println("login");
        //验证账号密码，底层会校验
        //底层校验通过，发token,写入响应头，响应前端
        String token = userService.login(user);
        response.setHeader("token", token);
        response.setHeader("Access-Control-Expose-Headers", "token");
        return new ResponseResult(200,"ok","login suceess");
    }
}
